#include <stdio.h>

int main(){
    int num;
    scanf("%d",&num);
    int target=0;
    scanf("%d",&target);
    int target0=target;
    int a[num];
    for (int i=0;i<num;i++){a[i]=i;}

    while (num!=1){
        while (target>num){target=target-num;}
      
        for (int i=target;i<num;i++){
            a[i-1]=a[i];
        }
        num--;
        target=target+target0-1;
        
       
    }
    printf("%d",a[0]);



    return 0;
}